import QtQuick 2.9
import "componentCreation.js" as MySprit
Rectangle{
    id:root
    width: 400
    height: 400
    color: "white"
    property var someNumber: 1.5
    property var someString: "abc"
    property var someBool: true
    property var someList: [1,2,"three","four"]
    property var someObject: Rectangle{
        width: 100
        height: 100
        color: 'red'
    }
    //states属性，存放的是State对象
    states:[
        State {
            name: "loading"
        },
        State{
            name:"runing"
        },
        State{
            name:"stopped"
        }
    ]
    SquareButton{
        x:200
        y:200
        //把邮槽函数放在外面
        onActivated: console.log("Activated at "+xPosition+","+yPosition)
        onDeactivated: console.log("Deactivated")
    }
    Image {
        id: image
        width: 300
        height: 200

        source: "pics/logo.png"
        anchors.centerIn: parent
    }

    Text {
        anchors{
            top: image.bottom
        }

        id: text
        property color nextColor
        property alias btn_text: text.text
        text: qsTr("QT的logo")
        font.family: "Helvetica"
        font.pointSize: 24
        font{
            pixelSize: 12
            bold: true
        }

        MouseArea{
            id:text_mouse
            anchors.fill: parent
            onClicked: {
                console.log("点击了")
                color:'red'
            }
        }
        onNextColorChanged: {
            console.log('color changed:'+nextColor)
        }
    }
    Rectangle{
        id:bt1
        anchors{
            top: text.bottom
        }
        anchors.margins: 20
        width: 300
        height: 200

        color: text.nextColor
        Text {
            id: tx1
            text: qsTr("点击它")
            font.pixelSize: 24
        }
        MouseArea{
            id:bt1_mouse
            anchors.fill: parent

        }
    }
    //一次一个
    Connections{
        target:bt1_mouse
        onClicked: {
            text.nextColor=Qt.rgba(Math.random(),Math.random(),Math.random(),1)
        }
    }
    signal messageReceived(string person,string notice)
    //一次多个
    Component.onCompleted: {
        root.messageReceived.connect(sendToPost)
        root.messageReceived.connect(sendToTelegraph)
        root.messageReceived.connect(sendToEmail)//信号邮槽相连
        root.messageReceived.connect(bt1_mouse.clicked)//信号与信号相连
        messageReceived("xxx","sss")//触发信号

        //动态创建对象
        MySprit.createSpriteObjects()
    }
    function sendToPost(person,notice){
        console.log("Sending to post:"+person+","+notice)
    }
    function sendToTelegraph(person,notice){
        console.log("Sending to telegraph:"+person+","+notice)
    }
    function sendToEmail(person,notice){
        console.log("Sending to email:"+person+","+notice)
    }
    enum TextType{
        Normal,
        Heading
    }

}
